package com.runchinaup.runchilibrary.modes.activity;

import android.content.Intent;
import android.support.v4.app.FragmentActivity;
import android.util.DisplayMetrics;
import android.view.View;
import android.widget.Toast;

/**
 * Created by liber on 2018/1/19.
 */

public class UtilActivity extends FragmentActivity {

    //Button button = $View(R.id.button);
    protected <T extends View> T $View(int id) {
        return (T) findViewById(id);
    }

    protected String $str(int id) {
        return getString(id);
    }

    /////////////////////////////////////////
    public FragmentActivity getUI() {
        return this;
    }

    public final void toast(final int id) {
        toast(getString(id));
    }

    public final void toast(final String msg) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(getUI(), msg, Toast.LENGTH_SHORT).show();
            }
        });
    }

    public final void toastLong(final int id) {
        toastLong(getString(id));
    }

    public final void toastLong(final String msg) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(getUI(), msg, Toast.LENGTH_LONG).show();
            }
        });
    }



    public void jump(Class<?> clz) {
        if (clz != null) {
            startActivity(new Intent(this, clz));
        }
    }

    public void jump(Intent intent) {
        startActivity(intent);
    }

    public void jumpAndFinish(Class<?> clazz) {
        startActivity(new Intent(this, clazz));
        finish();
    }

    public void onLeftClick(View view) {
    }

    public void onRightClick(View view) {
    }

    protected DisplayMetrics dm = new DisplayMetrics();
}
